package com.mlf.prototype.spring;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SingletonWithObjectProvider {

    @Autowired
    private ObjectProvider<PrototypeBean> prototypeBeanObjectProvider;

    public void getBean() {
        PrototypeBean bean1 = prototypeBeanObjectProvider.getObject();
        PrototypeBean bean2 = prototypeBeanObjectProvider.getObject();
        System.out.println("---Using ObjectProvider: --- ");
        System.out.println("bean1 :" + bean1.getInstanceId());
        System.out.println("bean2 :" + bean2.getInstanceId());
        System.out.println("bean1 == bean2 :" + (bean1 == bean2));
    }
}
